package com.bjsxt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.Coin;
import com.bjsxt.model.R;
import com.bjsxt.service.CoinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/coins")
@Api(tags = "数字货币数据接口")
public class CoinController {

    @Autowired
  private CoinService coinService;

    @GetMapping
    @ApiOperation(value = "数字货币分页查询条件")
    public R<Page<Coin>> findByPage(String name, String type , Byte status,
                                    String title, @RequestParam(value = "wallet_type",required = false)String walletType,
                                    Page<Coin>page){

        Page<Coin> coinPage = coinService.findByPage(name,type,status,title,walletType,page);

        return R.ok(coinPage);
    }

    @PostMapping("/setStatus")
    @ApiOperation(value = "禁用或启用币种")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "",value = "")
    })
    public R setStatus(@RequestBody Coin coin){
        boolean ok =  coinService.updateById(coin);
        if(ok){
            return R.ok();
        }
        return R.fail("设置姿态失败..");

    }

    @GetMapping("/info/{id}")
    @ApiOperation(value = "查询币种的详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "币种的id")
    })
    public R<Coin> info(@PathVariable("id")Long id){
        Coin coin = coinService.getById(id);
        return R.ok(coin);

    }
    
    @GetMapping("/all")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status",value = "币种当前的状态")
    })
    @ApiOperation(value ="通过状态查询所有的币种信息")
    public R<List<Coin>> getCoinAll(Byte status){
     List<Coin> coins =    coinService.getCoinByStatus(status);
     return R.ok(coins);
    }

    @PatchMapping
    @ApiOperation(value = "修改我们的币种信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coin",value ="coin json数据")
    })
    public R update(@RequestBody Coin coin){
        boolean ok = coinService.updateById(coin);
        if(ok){
            return R.ok();
        }

        return R.fail();
    }

    @PostMapping
    @ApiOperation(value = "修改我们的币种信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coin",value ="coin json数据")
    })
    public R<Coin> save(@RequestBody Coin coin){
        boolean ok = coinService.save(coin);
        if(ok){
            return R.ok(coin);
        }

        return R.fail("新增失败");
    }

































}
